package uml.view;

import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Panel;
import java.awt.TextArea;

import java.util.Iterator;

import javax.swing.BorderFactory;
import javax.swing.border.*;
public class ClassFormatter_View 
{
	//private Controller m_controller;
	private Container m_container;
	private Font m_font;
	private final float DEFAULTFONTSIZE = 12;
	/**
	 * Creates a <tt>ClassFormatter_View</tt> with a plain font of size 12;
	 */
	public ClassFormatter_View()
	{
		m_font = new Font(null, 0, (int)DEFAULTFONTSIZE);
	}
	/**
	 * Constructs formatter with <tt>Controller</tt> controller and a plain <tt>Font</tt> of size 12
	 * @param controller
	 */
//	public ClassFormatter_View(Controller controller)
//	{
//		m_controller = controller;
//	}
	/**
	 * Creates a <tt>ClassFormatter_View</tt> with <tt>Font</tt> f.
	 * @param f
	 */
	public ClassFormatter_View(Font f)
	{
		m_font = new Font(f.getAttributes());
	}
	/**
	 * Creates a <tt>ClassFormatter_View</tt> with <tt>Controller</tt> controller and <tt>Font</tt> f.
	 * @param controller
	 * @param f
	 */
//	public ClassFormatter_View(Controller controller, Font f)
//	{
//		m_controller = controller;		
//		m_font = new Font(f.getAttributes());
//	}
	/**
	 * Creates <tt>ClassFormatter_View</tt> with <tt>Container</tt> c and a plain <tt>Font</tt> object with a font size of 12
	 * <tt>Container</tt> is is not copied any changes the user makes to the <tt>Container</tt> will be made to the formatters <tt>Container</tt>
	 * @param c
	 */
	public ClassFormatter_View(Container c)
	{
		m_container = c;
		m_font = new Font(null, 0, (int)DEFAULTFONTSIZE);
	}
	/**
	 * Creates <tt>ClassFormatter_View</tt> with <tt>Controller</tt> controller, <tt>Container</tt> c and a plain <tt>Font</tt> object with a font size of 12
	 * <tt>Container</tt> is is not copied any changes the user makes to the <tt>Container</tt> will be made to the formatters <tt>Container</tt>
	 * @param controller
	 * @param c
	 */
//	public ClassFormatter_View(Controller controller, Container c)
//	{
//		m_controller = controller;
//		m_container = c;
//		m_font = new Font(null, 0, (int)DEFAULTFONTSIZE);
//	}
	/**
	 * Creats <tt>ClassFormatter_View</tt> with <tt>Container</tt> c and <tt>Font</tt> f
	 * <tt>Container</tt> is is not copied any changes the user makes to the <tt>Container</tt> will be made to the formatters <tt>Container</tt>
	 * @param c
	 * @param f
	 */
	public ClassFormatter_View(Container c, Font f)
	{
		m_container = c;
		m_font = new Font(f.getAttributes());
	}
	/**
	 * Creats <tt>ClassFormatter_View</tt> with <tt>Controller</tt> controller, <tt>Container</tt> c and <tt>Font</tt> f
	 * <tt>Container</tt> is is not copied any changes the user makes to the <tt>Container</tt> will be made to the formatters <tt>Container</tt>
	 * @param controller
	 * @param c
	 * @param f
	 */
//	public ClassFormatter_View(Controller controller, Container c, Font f)
//	{
//		m_container = c;
//		m_font = new Font(f.getAttributes());
//	}
	/**
	 * Sets <tt>Controller</tt> to controller
	 * @param controller
	 */
//	public void setController(Controller controller)
//	{
//		m_controller = controller;
//	}
	/**
	 * Sets <tt>Font</tt> to f
	 * @param f
	 */
	public void setFont(Font f)
	{
		m_font = new Font(f.getAttributes());
	}
	/**
	 * Sets <tt>Container</tt> to c
	 * <tt>Container</tt> is is not copied any changes the user makes to the <tt>Container</tt> will be made to the formatters <tt>Container</tt>
	 * @param c
	 */
	public void setContainer(Container c)
	{
		m_container = c;
	}
	/**
	 * Makes <tt>Font</tt> bold if the <tt>Font</tt> is italic it will set it to be both.
	 */
	public void setFontBold()
	{
		if (isFontItalic()) 
			m_font = m_font.deriveFont(Font.BOLD+Font.ITALIC);
		else if(!isFontBold())
			m_font = m_font.deriveFont(Font.BOLD);
		updateFont();
	}
	/**
	 * @return true if the <tt>Font</tt> is both bold and italic otherwise false.
	 */
	public boolean isFontBoldAndItalic() 
	{
		return m_font.isBold() && m_font.isItalic();
	}
	/**
	 * Makes <tt>Font</tt> italic if the <tt>Font</tt> is bold it will set it to be both.
	 */
	public void setFontItalic()
	{
		if (isFontBold()) 
			m_font = m_font.deriveFont(Font.BOLD+Font.ITALIC);
		else if(!isFontItalic())
			m_font = m_font.deriveFont(Font.ITALIC);
		updateFont();
	}
	/**
	 * sets <tt>font</tt> back to plain
	 */
	public void setFontPlain()
	{
		m_font = m_font.deriveFont(Font.PLAIN);
		updateFont();
	}
	/**
	 * @return true if <tt>Font</tt> is bold false otherwise
	 */
	public boolean isFontBold()
	{
		return m_font.isBold();
	}
	/**
	 * @return true if <tt>Font</tt> is bold false otherwise
	 */
	public boolean isFontItalic()
	{
		return m_font.isItalic();
	}
	/**
	 * @return true if <tt>Font</tt> is plain false otherwise
	 */
	public boolean isFontPlain()
	{
		return m_font.isPlain();
	}
	/**
	 * adds <tt>Panel</tt> P to <tt>Container</tt>
	 * @param p
	 */
	public void add(Panel p) 
	{
		m_container.add(p);
	}
	/**
	 * Sets the <tt>Container</tt>'s <tt>Font</tt> to the <tt>ClassFormatter_View</tt>'s <tt>Font</tt>
	 */
	public void updateFont()
	{
		m_container.setFont(m_font);
		for(int i = 0; i < m_container.getComponentCount(); ++i)
			m_container.getComponent(i).setFont(m_font);
	}
	/**
	 * sets the <tt>Font</tt> size to size.
	 * @param size
	 */
	public void setFontSize(float size)
	{
		m_font = m_font.deriveFont(size);
		updateFont();
	}
}